/**   
 * All rights Reserved, Designed By MiGu  
 * Copyright:    Copyright(C) 2016-2020  
 * Company       MiGu  Co., Ltd.
*/
package com.migu.spms.webapi;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.migu.spms.service.data.User;
import com.migu.spms.service.inf.IRequireExcelService;
import com.migu.spms.webapi.data.ExcelRequest;


/**   
 * RequireExcelController类
 * 项目名称:  SPMS功能需求
 * 包名称:    com.migu.spms.webapi   
 * 类名称:    RequireExcelController.java
 * 类描述:    
 * 创建人:    wcr   
 * 创建时间:  2017年7月4日 上午10:12:20   
 */
@Controller
@RequestMapping(value = "/cdyuheng", produces = "application/json;charset=UTF-8")
public class RequireExcelController extends BaseController {

    private static Logger logger = LoggerFactory.getLogger(RequireExcelController.class);

    @Resource(name = "requireExcelServiceImpl")
    private IRequireExcelService requireExcelService;
    /**
     * Excel导出
     * @param req
     * @param resp
     * @param sessionId
     * @return
     * @throws Exception
     * @exception
     * @throws
     */
     @ResponseBody  
     @RequestMapping(value = "/exportExcel")
     public String exportExcel(HttpServletRequest req, HttpServletResponse resp,String sessionId) throws Exception{
         User user = getUserBySession(req, sessionId);
         if (user == null) {
             return generateResponse(401);
         }
         ExcelRequest msg = ParseMsg(req, ExcelRequest.class);

         requireExcelService.exportRequireInfo(msg, req, resp);
         return "";
     }
     
     /**
    * Excel导入
    * @param req
    * @param resp
    * @param sessionId
    * @return
    * @throws Exception
    * @exception
    * @throws
    */
    @ResponseBody  
     @RequestMapping(value = "/readExcel")
     public String readExcel(@RequestParam(value="excelFile") MultipartFile file, 
             HttpServletRequest req, HttpServletResponse resp,String sessionId) throws Exception{
         User user = getUserBySession(req, sessionId);
         if (user == null || null == file) {
             return generateResponse(401);
         }
         ExcelRequest msg = ParseMsg(req, ExcelRequest.class);

         requireExcelService.readExcel(msg, file);
         return generateResponse(200);
     }
}
